#include "CFunction.h"

CFunction::CFunction(char* code,  int codeSize, int paramCount, QHash<QString, char*> variables, QVector<QString>* parameters)
{
    _action = nullptr;
    _code = code;
    _codeSize = codeSize;
    _paramCount = paramCount;
    _variables = variables;
    _parameters = parameters;
}

CFunction::CFunction(CAction action, int paramCount, QHash<QString, char*> variables, QVector<QString>* parameters)
{
    _action = action;
    _code = nullptr;
    _codeSize = -1;
    _paramCount = paramCount;
    _variables = variables;
    _parameters = parameters;
}

CFunction::~CFunction()
{
    //need to copy parameters, when creating the frame
    //for (int i = 0; i < _variables.values().size(); i++) delete _variables.values()[i];
    //delete _parameters;
}

char* CFunction::code()
{
    return _code;
}

int CFunction::codeSize()
{
    return _codeSize;
}

CAction CFunction::action()
{
    return _action;
}

int CFunction::paramCount()
{
    return _paramCount;
}

bool CFunction::isNative()
{
    return _action != nullptr;
}

QHash<QString, char*>& CFunction::variables()
{
    return _variables;
}

QVector<QString>& CFunction::parameters()
{
    return *_parameters;
}
